/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

using System;

using TypeElement = argot.TypeElement;
using TypeException = argot.TypeException;
using TypeInputStream = argot.TypeInputStream;
using TypeOutputStream = argot.TypeOutputStream;
using TypeReader = argot.TypeReader;
using TypeWriter = argot.TypeWriter;

namespace argot.common
{
	
	/// <summary> 
	/// The BOOL type is a single U8 character which has the value 0 or 1.
	/// if the actual value is anything other than 0 the final object will
	/// be true.
	/// </summary>
	public class U8Boolean 
	:TypeReader, TypeWriter
	{
		public const System.String TYPENAME = "bool";
		
		public virtual System.Object Read(TypeInputStream inStream, TypeElement element)
		{
			int a;
			
			a = inStream.Stream.ReadByte();
			
			return a == 0?false:true;
		}
		
		public virtual void Write(TypeOutputStream outStream, System.Object o, TypeElement element)
		{
			int a;

			if (o is System.Boolean)
			{
				a = ((System.Boolean) o) == false?0:1;
			}
			else
				throw new TypeException("U8Boolean requires Boolean object");
			
			outStream.Stream.WriteByte((byte)a);
		}
	}
}